package com.hmall.trade.listener;

import com.hmall.trade.service.IOrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 订单支付结果状态更新监听器
 *
 * @Author mr.wu
 * @Date 2025-8-24 17:46
 */
@RequiredArgsConstructor
@Component
@Slf4j
public class OrderStatusUpdateListener {

    private final IOrderService orderService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "trade.pay.success.queue"),
            exchange = @Exchange(name = "pay.direct", type = ExchangeTypes.DIRECT),
            key = "pay.success" ))
    public void listenOrderNoMsg(String orderId) {
        orderService.markOrderPaySuccess(Long.valueOf(orderId));
        log.info("[更新订单状态]消费到订单ID：{}，更新订单状态完毕", orderId);
    }
}
